/**
 * Copyright (c) 2010 CEPRI,Inc.All rights reserved.
 * Created by 2018-3-8
 */
package com.yunfei.api.user.contants;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @title :系统参数格式校验常量类
 * @description :
 * @author: zhengYunFei
 */
public class ValitationConstant {
    // 手机号码格式校验
    public static final String MOBILE_REG = "^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})|(19[0-9]{9})$"; //手机号码格式校验
    //密码格式校验
    public static final String PASSWORD_REG = "^[A-Za-z0-9]{6,20}$";
    public static final int MIN_LENGTH = 6;//密码最小长度
    //验证正整数
    public static final String NUM_REG = "^[+]{0,1}(\\d+)$";
    //正数（包括小数）
    public static final String NUMBER_REG = "^[+]{0,1}(\\d+)$|^[+]{0,1}(\\d+\\.\\d+)$";
    //校验是否是字母
    public static final String LETTER_REG = "[a-zA-Z]+$";

    public static void main(String args[]) {
        System.out.println(isPhone("177409664979"));

    }

    public static boolean isPhone(String phone) {
        String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";
        if (phone.length() != 11) {
            System.out.println("手机号应为11位数");
            return false;
        } else {
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(phone);
            boolean isMatch = m.matches();
            System.out.println(isMatch);
            if (!isMatch) {
                System.out.println("请填入正确的手机号");
            }
            return isMatch;
        }
    }
}

